home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / btnc200 / parser.c < prev    next >
C/C++ Source or Header  |  1996-09-11  |  10KB  |  478 lines

  1. /*
  2. **    Program:    BTNC
  3. **
  4. **    Module:        Nodelist line parser
  5. */
  6.  
  7. #include        <portab.h>
  8.  
  9. #include        <stdlib.h>
  10. #include        <string.h>
  11.  
  12. #include        "general.h"
  13. #include        "globals.h"
  14. #include        "prototyp.h"
  15. #include        "logfile.h"
  16.  
  17. UWORD            last_node;    /* OB */
  18.  
  19. WORD ParseLine(WORD type, BYTE *NLline, INDEX *idx, SYSTEM *sys, UWORD nl_lines)
  20. {
  21.     BYTE    line[1024],
  22.             *nextstart,
  23.             attr[100],
  24.             valstr[100],
  25.             field[100],
  26.             namebuf[100],
  27.             namebuf2[100],
  28.             hostname[34],
  29.             *name1,
  30.             *name2;
  31.     WORD    val;
  32.     
  33.     CleanString(NLline, line);
  34.     
  35.     nextstart = NextField(line, attr);
  36.     nextstart = NextField(nextstart, valstr);
  37.     val = atoi(valstr);
  38.     
  39.     idx->value = val;
  40.     
  41.     if ((idx->type = type) == NODE)
  42.     {
  43.         curaddr.node = val;
  44.         curaddr.point = 0;
  45.     }
  46.     else
  47.         curaddr.point = val;
  48.     
  49.     if (*attr)
  50.     {
  51.         if (*attr == 'H' && attr[2] == 's')
  52.         {
  53.             idx->type = HOST;
  54.             curaddr.net = val;
  55.             curaddr.node = curaddr.point = curhub = 0;
  56.         }
  57.         else
  58.             if (*attr == 'H' && attr[1] == 'u')
  59.             {
  60.                 idx->type = HUB;
  61.                 curhub = val;
  62.             }
  63.             else
  64.                 if (*attr == 'D') return(DOWN);
  65.                 else
  66.                     if (*attr == 'R')
  67.                     {
  68.                         if (doing_addlist) return(SKIP);
  69.                         
  70.                         idx->type = RC;
  71.                         
  72.                         /*
  73.                         ** remember last region number;
  74.                         */
  75.                         
  76.                         curaddr.net = curreg = val;
  77.                         curaddr.node = curaddr.point = curhub = 0;
  78.                         regions++;
  79.                     }
  80.                     else
  81.                         if (*attr == 'P')
  82.                         {
  83.                             sys->flags |= PRIVATE;
  84.                             private_nodes++;
  85.  
  86. /* Modified : -------------------- */
  87.                             if(    ADDLIST4D==TRUE)
  88.                             {
  89.                                 idx->type = POINT;
  90.                                 curaddr.node=last_node;
  91.                                 curaddr.point =    val;
  92.                             }
  93. /* ------------------------------- */
  94.  
  95.                         }
  96.                         else
  97.                             if (*attr == 'H' && attr[2] == 'l')
  98.                                 sys->flags |= HOLD;
  99.                             else
  100.                                 if (*attr == 'Z')
  101.                                 {
  102.                                     if (doing_addlist) return(SKIP);
  103.                                     
  104.                                     idx->type = ZC;
  105.                                     curaddr.zone = curreg = curaddr.net = val;
  106.                                     curaddr.node = curaddr.point = curhub = 0;
  107.                                     
  108.                                     if (curaddr.zone == onlyzone)
  109.                                         oz_compiled = TRUE;
  110.                                     if (display && az_compiled)
  111.                                         ALL_puts("");
  112.                                 }
  113.     }
  114.  
  115. /* Modified OB ---------------------*/
  116.  
  117.     else if (ADDLIST4D==TRUE)        /* ',' seems to be a NODE */
  118.     {
  119.         last_node=val;
  120.     }
  121.     
  122. /* ---------------------------------*/    
  123.     if (onlyzone && oz_compiled && curaddr.zone != onlyzone)
  124.     {
  125.         active_nodes--;
  126.         oz_compiled = FALSE;
  127.         
  128.         return(ABORT);
  129.     }
  130.     
  131.     if (onlyzone && curaddr.zone != onlyzone) return(SKIP);
  132.     
  133.     if (*attr == 'Z') zones++;
  134.     
  135.     if (nextstart)
  136.     {
  137.         nextstart = NextField(nextstart, field);
  138.         ReplaceUnderscores(field);
  139.         strncpy(sys->sysname, field, 33L);
  140.         
  141.         /*
  142.         ** Take hostname into memory (for compiling a userlist of the
  143.         ** new german points24 format)
  144.         */
  145.         
  146.         if (idx->type == HOST) strncpy(hostname, sys->sysname, 33L);
  147.  
  148. /* Modified -------------------- */    
  149.  
  150.         else if(ADDLIST4D==TRUE && idx->type == NODE)
  151.             strncpy(hostname, sys->sysname, 33L);
  152.  
  153. /* ----------------------------- */
  154.  
  155.     }
  156.     else
  157.     {
  158.         ERR_printf ("\nLine %u: Missing system name\n", nl_lines);
  159.         return (ABORT);
  160.     }
  161.     
  162.     if (nextstart)
  163.     {
  164.         nextstart = NextField(nextstart, field);
  165.         ReplaceUnderscores(field);
  166.         strncpy(sys->location, field, 29L);
  167.     }
  168.     else
  169.     {
  170.         ERR_printf("\nLine %u: Missing location\n", nl_lines);
  171.         return (ABORT);
  172.     }
  173.     
  174.     
  175.     if (nextstart)
  176.     {
  177.         nextstart = NextField(nextstart, field);
  178.         ReplaceUnderscores(field);
  179.         strncpy(sys->operator, field, 29L);
  180.     }
  181.     else
  182.     {
  183.         ERR_printf ("\nLine %u: Missing operator name\n", nl_lines);
  184.         return (ABORT);
  185.     }
  186.     
  187.     if (nextstart)
  188.     {
  189.         nextstart = NextField(nextstart, field);
  190.         strncpy (sys->phone, field, 39L);
  191.  
  192. /* Modified OB ---------------------*/
  193.  
  194. /*        
  195.         if (idx->type == ZC || idx->type == RC || idx->type == HOST || idx->type == HUB)
  196.             strcpy(hubphone, sys->phone);
  197.             
  198.         if ((sys->flags & PRIVATE) && *hubphone)
  199.             strcpy(sys->phone, hubphone);
  200.     }
  201. */
  202.  
  203.         if ( !(sys->flags & PRIVATE ) )
  204.             if ( stricmp(sys->phone,"-Unpublished-") !=0 )
  205.                 strcpy(hubphone, sys->phone);
  206.             
  207.         if ((sys->flags & PRIVATE) && *hubphone)
  208.         {
  209.             if ( stricmp(sys->phone,"-Unpublished-") ==0 )
  210.                 strcpy(sys->phone, hubphone);
  211.         }
  212.     }
  213.     
  214. /* ----------------------------------*/
  215.  
  216.     else
  217.     {
  218.         ERR_printf ("\nLine %u: Missing phone number\n", nl_lines);
  219.         return (ABORT);
  220.     }
  221.     
  222.     if (nextstart)
  223.     {    
  224.         nextstart = NextField(nextstart, valstr);
  225.         sys->maxbaud = atoi(valstr)/300;
  226.     }
  227.     else
  228.     {
  229.         ERR_printf ("\nLine %u: Missing baudrate\n", nl_lines);
  230.         return (ABORT);
  231.     }
  232.     
  233.     sys->hubnode = curhub;
  234.     
  235.     if (userlist)
  236.     {
  237.         strcpy(namebuf, sys->operator);
  238.         name1 = strtok(namebuf, " ");
  239. /* Modified --------------------- */
  240. /*        name2 = strtok(NULL, " ");    */
  241.         name2 = strtok(NULL, "");
  242. /* ------------------------------ */
  243.  
  244.         if (name2)
  245.         {
  246.             strcpy(namebuf2, name2);
  247.             strcat(namebuf2, ", ");
  248.             strcat(namebuf2, name1);
  249.         }
  250.         else
  251.         {
  252.             if (name1)
  253.                 strcpy(namebuf2, name1);
  254.             else
  255.                 strcpy(namebuf2, "-Unknown-");
  256.         }
  257.  
  258. /* Modified -------------------- */
  259.         /* Rajoute les points 4d dans la fidouser.lst */
  260.  
  261.         if (ADDLIST4D==TRUE && idx->type == POINT)    doing_addlist=FALSE;
  262.  
  263. /* ----------------------------- */
  264.         
  265.         if (doing_addlist)
  266.         {
  267.             if (points24)           
  268.             /*
  269.                 fprintf(fidouser_lst, "%s %u:%s\n", namebuf2,
  270.                     curaddr.zone, sys->sysname);
  271.             */
  272.  
  273.             /*
  274.             ** New format of Points24 
  275.             */
  276.             
  277.                 if (curaddr.node)
  278.                 {
  279.                     fprintf(fidouser_lst, "%s %u:%s.%u\n", namebuf2,curaddr.zone, hostname, curaddr.node);
  280.                 }
  281.         }
  282.         else
  283.         {
  284.             if (curaddr.point == 0)
  285.             {
  286.                 fprintf(fidouser_lst, "%s %u:%u/%u\n", namebuf2,curaddr.zone, curaddr.net, curaddr.node);
  287.             }
  288.             else
  289.             {
  290.                 fprintf(fidouser_lst, "%s %u:%u/%u.%u\n", namebuf2,curaddr.zone, curaddr.net, curaddr.node, curaddr.point);
  291.             }
  292.         }
  293.     }
  294.     
  295.     while (nextstart && *nextstart)
  296.     {
  297.         nextstart = NextField(nextstart, field);
  298.         
  299.         if (*field != 'X' && *field != 'U' && *field != 'I') 
  300.         {
  301.             if (*field == 'C' && field[1] == 'M')
  302.                 sys->flags |= CM;
  303.             else
  304.                 if (*field == 'H')
  305.                 {
  306.                     if (field[1] == '1' && field[2] == '4')
  307.                         sys->modemtype |= HST;
  308.                     else
  309.                         if (field[1] == '1' && field[2] == '6')
  310.                             sys->modemtype |= H16;
  311.                 }
  312.                 else
  313.                     if (*field == 'Z')
  314.                     {
  315.                         if (field[1] == '1' && field[2] == '9')
  316.                             sys->modemtype |= Z19;
  317.                         else
  318.                             sys->modemtype |= ZYX;
  319.                     }
  320.                     else
  321.                         if (*field == 'M' && field[1] == 'N' && field[2] == 'P')
  322.                             sys->modemtype |= MNP;
  323.                         else
  324.                         {
  325.                             if (*field == 'M' && field[1] == 'O')
  326.                                 sys->flags |= MAILONLY;
  327.                             else
  328.                                 if (*field == 'V')
  329.                                     if (field[2] == '2')
  330.                                     {
  331.                                         if (field[1] == '3')
  332.                                         {
  333.                                             if (field[3] == 'B')
  334.                                                 sys->modemtype |= V32B;
  335.                                             else
  336.                                                 if (field[3] == 'T')
  337.                                                     sys->modemtype |= V32T;
  338.                                         }
  339.                                         else
  340.                                             if (field[1] == '4')
  341.                                             {
  342.                                                 if (field[3] == 'B')
  343.                                                     sys->modemtype |= V42B;
  344.                                                 sys->modemtype |= V42;
  345.                                             }
  346.                                     }
  347.                                     else
  348.                                     {
  349.                                         if (field[2] == '4' && field[1] == '3')
  350.                                             sys->modemtype |= V34;
  351.                                         else
  352.                                         {
  353.                                             if (field[2] == 'C' && field[1] == 'F')
  354.                                                 sys->modemtype |= V34;
  355.                                             else
  356.                                                 if (field[2] == '1')
  357.                                                 {
  358.                                                     if (field[4] == 'L')
  359.                                                         sys->modemtype |= ISDNA;
  360.                                                     else
  361.                                                         sys->modemtype |= ISDNB;
  362.                                                 }
  363.                                         
  364.                                         }
  365.                                     }
  366.                                 else
  367.                                 {
  368.                                     if (*field == 'M' && field[1] == 'A' && field[2] == 'X')
  369.                                         sys->modemtype |= MAX;
  370.                                     else
  371.                                         if (*field == 'M' && field[1] == 'N')
  372.                                             sys->flags |= NOARCMAIL;
  373.                                 }
  374.                         }
  375.         }
  376.         else
  377.         {
  378.             if (*field == 'X')
  379.             {
  380.                 switch (field[1])
  381.                 {
  382.                     case    'A':
  383.                         sys->flags |= BARKREQ;
  384.                         sys->flags |= BARKUPDREQ;
  385.                         sys->flags |= WAZOOREQ;
  386.                         sys->flags |= WAZOOUPDREQ;    break;
  387.                     case    'B':
  388.                         sys->flags |= BARKREQ;
  389.                         sys->flags |= BARKUPDREQ;
  390.                         sys->flags |= WAZOOREQ;        break;
  391.                     case    'P':
  392.                         sys->flags |= BARKREQ;
  393.                         sys->flags |= BARKUPDREQ;    break;
  394.                     case    'R':
  395.                         sys->flags |= BARKREQ;
  396.                         sys->flags |= WAZOOREQ;        break;
  397.                     case    'W':
  398.                         sys->flags |= WAZOOREQ;        break;
  399.                     case    'X':
  400.                         sys->flags |= WAZOOREQ;
  401.                         sys->flags |= WAZOOUPDREQ;    break;
  402.                     case    '7':
  403.                         sys->modemtype |= ISDNC;
  404.                 }
  405.             }
  406.             else
  407.             {
  408.                 if (*field == 'U')
  409.                 {
  410.                     if (field[1] == 'I' && field[2] == 'S' && field[3] == 'D' && field[4] == 'N')
  411.                     {
  412.                         switch (field[5])
  413.                         {
  414.                             case 'A':
  415.                                 sys->modemtype |= ISDNA;
  416.                             case 'B':
  417.                                 sys->modemtype |= ISDNB;
  418.                             case 'C':
  419.                                 sys->modemtype |= ISDNC;
  420.                         }
  421.                     }
  422.                     else 
  423.                     if (field[1] == 'V' && field[2] == '1' && field[3] == '1' && field[4] == '0')
  424.                     {
  425.                         switch (field[5])
  426.                         {
  427.                             case 'L':
  428.                                 sys->modemtype |= ISDNA;
  429.                             case 'H':
  430.                                 sys->modemtype |= ISDNB;
  431.                         }
  432.                     }
  433.                     else
  434.                         if (field[1] == 'V' && field[2] == '3')
  435.                         {
  436.                             if (field[3] == '2' && field[4] == 'T')
  437.                                 sys->modemtype |= (V32T|V32B|V32|MNP);
  438.                             else if (field[3] == '4')
  439.                                 sys->modemtype |= (V34|V32B|V32|MNP);
  440.                         }
  441.                         else
  442.                         if (field[1] == 'X' && field[2] == '7')
  443.                             sys->modemtype |= ISDNC;
  444.                                 
  445.                 }
  446.                 else
  447.                 {
  448.                     if (field[1] == 'S' && field[2] == 'D' && field[3] == 'N')
  449.                     {
  450.                         switch (field[4])
  451.                         {
  452.                             case 'A':
  453.                                 sys->modemtype |= ISDNA;
  454.                             case 'B':
  455.                                 sys->modemtype |= ISDNB;
  456.                             case 'C':
  457.                                 sys->modemtype |= ISDNC;
  458.                         }
  459.                     }
  460.                     else
  461.                     if (field[0] == 'V' && field[1] == '1' && field[2] == '1' && field[3] == '0')
  462.                     {
  463.                         switch (field[4])
  464.                         {
  465.                             case 'L':
  466.                                 sys->modemtype |= ISDNA;
  467.                             case 'H':
  468.                                 sys->modemtype |= ISDNB;
  469.                         }
  470.                     }
  471.                 }
  472.             }
  473.         }
  474.     }
  475.     
  476.     return(OK);
  477. }
  478.